var app = getApp();
Page({
  data: {
    section: [{
        name: '全部',
        typeId: '1'
      },
      {
        name: '待付款',
        typeId: '2'
      },
      {
        name: '未成团',
        typeId: '3'
      },
      {
        name: '待使用',
        typeId: '4'
      },
      {
        name: '已完成',
        typeId: '5'
      }
    ],
    currentId: '1',
    page: 1,
    no_more: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var store_id = wx.getStorageSync("store_id");
    if(!store_id){
      wx.navigateTo({
        url: '/pages/index/index'
      });
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var store_id = wx.getStorageSync("store_id");
    if(!store_id){
      wx.navigateTo({
        url: '/pages/index/index'
      });
    }else{
      // 获取订单列表
      this.getOrderList();
    }
  },

  /**
   * 获取订单列表
   */
  getOrderList: function () {
    let _this = this;
    var page = _this.data.page;
    var store_id = wx.getStorageSync("store_id");
    app.acc5ShowLoading(_this)
    app.visit('account/getPinTuanOrderLists?page='+page, {
      type:_this.data.currentId,
      store_id:store_id
    }, '',function (result) {
      var lls = result.data;
      console.log(lls)
      if (lls.length < 10) {
        _this.setData({
          no_more: true
        })
      }
      app.acc5HideLoading(_this)
      console.log("订单列表", result);
      if (page == 1) {
        _this.setData({
          list: lls,
          page: page + 1
        })
      } else {
        var list = _this.data.list.concat(lls)
        _this.setData({
          list: list,
          page: page + 1
        })
      }
    });
  },

  /**
   * 下拉到底加载数据
   */
  onReachBottom: function () {
    // 已经是最后一页
    if (this.data.no_more == true) {
      return false;
    } else {
      this.getOrderList();
    }
  },

  handleTap: function(e) {
    let id = e.currentTarget.id;
    this.setData({
      currentId: id,
      page:1,
      no_more: false,
    })
    this.getOrderList();
  },

  pt_detail: function (e) {
    var order_id = e.currentTarget.dataset.order_id
    wx.navigateTo({
      url: 'pt_detail?order_id='+order_id
    });
  },

})